/*
 * @Author: 2112778581 2112778581@qq.com
 * @Date: 2023-10-16 10:13:29
 * @LastEditors: fengshan525 2735332396@qq.com
 * @LastEditTime: 2023-10-31 21:25:51
 * @FilePath: \pra\libs\db\src\models\news.model.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ApiProperty } from '@nestjs/swagger';
import { modelOptions, prop, Ref } from '@typegoose/typegoose';
import { IsNotEmpty, Allow } from 'class-validator';
import { Category } from './category.model';

@modelOptions({
  // 自动为每个属性添加时间戳
  schemaOptions: {
    timestamps: true,
  },
})
export class News {
  @ApiProperty({ description: '新闻标题' })
  @IsNotEmpty({ message: '新闻内容不能为空' })
  @prop()
  title: string;

  @ApiProperty({ description: '新闻描述' })
  @IsNotEmpty({ message: '新闻描述不能为空' })
  @prop()
  desc: string;

  @ApiProperty({ description: '新闻内容', required: true })
  @IsNotEmpty({ message: '新闻内容不能为空' })
  @prop()
  content: string;

  @ApiProperty({ description: '新闻图片', required: true })
  @IsNotEmpty({ message: '新闻图片不能为空' })
  @prop()
  pic: string;

  @ApiProperty({ description: '是否发布新闻', required: true })
  @IsNotEmpty({ message: '是否发布新闻' })
  @prop()
  isPublished: boolean;

  @ApiProperty({ description: '是否推荐新闻', required: true })
  @IsNotEmpty({ message: '是否推荐新闻' })
  @prop()
  isRecommend: boolean;

  // 1. xx 2.xx 3.xx 4.xx 枚举值
  @IsNotEmpty({ message: '新闻分类不能为空' })
  @prop({ ref: () => Category })
  category: Ref<Category>;

  @Allow()
  _id: string;

  @Allow()
  createdAt: string;

  @Allow()
  updatedAt: string;

  @Allow()
  __v: string;
};